
capture cd "~/Replication/afrobarometer"
clear


*****************************
***   Append all rounds   ***
*****************************


do "ab r1 cleaning.do"
tempfile r1
save `r1'

do "ab r2 cleaning.do"
tempfile r2
save `r2'

do "ab r3 cleaning.do"
tempfile r3
save `r3'


do "ab r4 cleaning.do"
tempfile r4
save `r4'

do "ab r5 cleaning.do"
tempfile r5
save `r5'

do "ab r6 cleaning.do"
tempfile r6
save `r6'

do "ab r7 cleaning.do"
tostring day, replace
append using `r6'
append using `r5'
append using `r4'
append using `r3'
append using `r2'

merge 1:1 round respno using "r3 to r7 geocoded.dta", update replace
drop if _merge == 2

order round respno provincepc-new_lon month day year
drop _merge


append using `r1'

merge 1:1 round respno using "zim r1-r2 geocoded.dta", update replace
drop if _merge == 2

order round respno provincepc province districtpc district

replace province = proper(province)
replace district = proper(district)
replace district = "Harare" if district == "Harare Urban"
replace province = subinstr(province, "Mash ", "Mashonaland ", .)
replace province = subinstr(province, "Mat ", "Matabeleland ", .)
replace province = subinstr(province, "Matebeleland", "Matabeleland", .)

replace district = "Mount Darwin" if district == "Mt Darwin"
replace district = "Masvingo" if district == "Masvingo Rural"
replace district = "Zvishavane" if district == "Zvishavane Rural"
replace district = "Kwekwe" if district == "Kwekwe Rural"
replace district = "Gweru" if district == "Gweru (Lower)" | district == "Gweru Rural"
replace district = "Beitbridge" if district == "Beit-Bridge"
replace district = "Bulilima" if strpos(district, "Bulilima") > 0
replace district = "Matobo" if district == "Matopo"
replace district = "Gokwe South Urban" if district == "Gokwe Urban"
replace district = "Redcliff" if district == "Red Cliff"
replace district = "Chirumhanzu" if district == "Chirumanzu"
replace district = "Uzumba Maramba Pfungwe" if district == "Ump"
replace district = "Hwedza" if district == "Wedza"
replace district = "Kadoma Urban" if district == "Kadoma"
replace district = "Centenary" if district == "Muzarabani"
replace district = "Gwanda" if district == "Gwanda Rural"
replace district = "Ruwa" if district == "Ruwa Lb"

gsort province -provincepc district -districtpc
bys province: carryforward provincepc, replace
bys province district: carryforward districtpc, replace

gsort province -provincepc district -districtpc
bys province: carryforward provincepc, replace
bys province district: carryforward districtpc, replace

sort round respno
gen id = _n
drop _me

destring day, replace
order day month year, after(round)
ren day interview_day
ren month interview_month
ren year interview_year

save "../data/Zimbabwe AB all coding.dta", replace





